import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import '../../theme/jr.dart';

class JRTextField extends StatelessWidget {
  final String? title;
  final String? suffix;
  final String? initText;
  final TextEditingController? controller;
  final bool autofocus;
  final FocusNode? focusNode;
  final TextInputType? keyboardType;
  final List<TextInputFormatter>? inputFormatters;

  // final InputDecoration? decoration;
  final String hintText;
  final ValueChanged<String>? onChanged;

  final TextStyle? titleStyle;
  final TextStyle? suffixStyle;
  final double? height;
  final Color? bgColor;

  const JRTextField(
      {Key? key,
      this.title,
      this.titleStyle,
      this.suffix,
      this.suffixStyle,
      this.initText,
      this.controller,
      this.autofocus = false,
      this.focusNode,
      this.keyboardType,
      this.inputFormatters,
      this.height,
      this.bgColor,
      required this.hintText,
      this.onChanged})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.symmetric(horizontal: 20),
      height: height ?? 48.h,
      width: double.infinity,
      decoration: ShapeDecoration(
        shape: const StadiumBorder(),
        color: bgColor ?? const Color(0xFFFAFAFA),
      ),
      child: Row(
        children: [
          if (title != null)
            Text(
              title!,
              style: titleStyle ??
                  TextStyle(
                    color: const Color(0xFF666666),
                    fontSize: 16.sp,
                    fontWeight: FontWeight.w400,
                    height: 16 / 16,
                  ),
            ),
          if (title != null)
            const SizedBox(
              width: 12,
            ),
          if (title != null)
            Container(
              width: 1,
              height: 18,
              color: const Color(0x7FD5D5D5),
            ),
          if (title != null)
            const SizedBox(
              width: 12,
            ),
          Expanded(
            child: TextField(
              controller: controller,
              autofocus: autofocus,
              focusNode: focusNode,
              keyboardType: keyboardType,
              inputFormatters: inputFormatters,
              cursorHeight: 18.h,
              cursorWidth: 2.w,
              cursorColor: JR.color.cursorColor,
              decoration: InputDecoration(
                contentPadding: const EdgeInsets.only(bottom: 2),
                border: InputBorder.none,
                hintText: " $hintText",
                hintStyle: TextStyle(
                    fontSize: 14.sp,
                    color: const Color(0xFFD5D5D5),
                    fontWeight: FontWeight.w400,
                    height: 1), //设置提示文字样式
              ),
              style: TextStyle(
                  fontSize: 16.sp,
                  color: const Color(0xFF333333),
                  // height: 1,
                  fontWeight: FontWeight.w500),
              onChanged: onChanged,
            ),
          ),
          if (suffix != null)
            const SizedBox(
              width: 12,
            ),
          if (suffix != null)
            Text(
              suffix!,
              style: suffixStyle ??
                  TextStyle(
                    color: const Color(0xFF666666),
                    fontSize: 15.sp,
                    fontWeight: FontWeight.w600,
                    height: 16 / 16,
                  ),
            ),
        ],
      ),
    );
  }
}
